<?php

/**
 * Classe prenant en charge les requetes SQL de type [UPDATE]
 *
 * @category   McCube
 * @package    Db
 * @author     Leiha Sellier <leiha.sellier@gmail.com>
 * @license    http://creativecommons.org/licenses/by/3.0/  CC BY 3.0
 * @link       http://code.google.com/p/mechanics-cubes/
 * @see        http://www.php.net/manual/book.pdo.php
 */
class McCube_Db_Query_Update extends McCube_Db_Query{

    public function build(){
        $q = 'UPDATE '.$this->_table
            .' SET '.implode(' , ', $this->_values)
        ;

        if(!empty($this->_where))
           $q .= ' WHERE '.$this->_where;

        if(!empty($this->_orderBy))
            $q .= ' ORDER BY '.$this->_orderBy;

        if(!empty($this->_limit))
            $q .= ' LIMIT '.$this->_limit;

        return $q.';';
    }

     public function set($field, $value){
        if(is_array($field))
            $this->sets($field);
        else
            $this->_values[$field] = $field.'="'.$value.'"';

        return $this;
    }

    public function sets($sets){
        foreach($sets as $field => $value)
            $this->set($field, $value);

        return $this;
    }


}